home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / vtskt10i.zip / TELNET.FRM < prev    next >
Text File  |  1994-02-13  |  25KB  |  1,056 lines

  1. VERSION 2.00
  2. Begin Form telnet_form 
  3.    BackColor       =   &H00FFFFFF&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Telnet"
  6.    ClientHeight    =   4020
  7.    ClientLeft      =   1380
  8.    ClientTop       =   2580
  9.    ClientWidth     =   6135
  10.    DrawMode        =   16  'Whiteness
  11.    FontBold        =   0   'False
  12.    FontItalic      =   0   'False
  13.    FontName        =   "Host Presenter"
  14.    FontSize        =   9
  15.    FontStrikethru  =   0   'False
  16.    FontUnderline   =   0   'False
  17.    Height          =   4710
  18.    Left            =   1320
  19.    LinkMode        =   1  'Source
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    MinButton       =   0   'False
  23.    ScaleHeight     =   4020
  24.    ScaleWidth      =   6135
  25.    Top             =   1950
  26.    Width           =   6255
  27.    Begin WinSock WinSock1 
  28.       Client_or_Server=   0  'Client
  29.       Interval        =   0
  30.       IPName          =   ""
  31.       Left            =   600
  32.       LicDate         =   0
  33.       License1        =   ""
  34.       License2        =   ""
  35.       Licensed        =   0
  36.       Linger          =   0   'False
  37.       Port            =   0
  38.       RecvBufSize     =   0
  39.       SendBufSize     =   0
  40.       Top             =   60
  41.    End
  42.    Begin Timer cursor_timer 
  43.       Interval        =   300
  44.       Left            =   90
  45.       Top             =   60
  46.    End
  47.    Begin Menu telnet_file_menu 
  48.       Caption         =   "&File"
  49.       Begin Menu menu_connect 
  50.          Caption         =   "&Connect"
  51.       End
  52.       Begin Menu menu_disconnect 
  53.          Caption         =   "&Disconnect"
  54.       End
  55.       Begin Menu menu_exit 
  56.          Caption         =   "&Exit"
  57.       End
  58.    End
  59.    Begin Menu font_menu 
  60.       Caption         =   "Fonts"
  61.       Begin Menu font_7_menu 
  62.          Caption         =   "7 Point"
  63.          Checked         =   -1  'True
  64.       End
  65.       Begin Menu font_9_menu 
  66.          Caption         =   "9 Point"
  67.       End
  68.    End
  69. End
  70. Dim insert_mode As Integer
  71. Dim parm(9) As Integer
  72. Dim pno As Integer
  73. Dim row As Integer
  74. Dim col As Integer
  75. Dim save_row As Integer
  76. Dim save_col As Integer
  77. Dim comm_buffer(23) As String * 80
  78.  
  79. Dim control_on As Integer
  80.  
  81. Dim cursor_is_on As Integer
  82.  
  83. Dim tabno As Integer
  84. Dim tab_table(20) As Integer
  85.  
  86. Dim txth As Integer
  87. Dim txtw As Integer
  88.  
  89. Dim graphics As Integer
  90. Dim graph_chars As String
  91. Dim attributes As Integer
  92.  
  93. Const ATTR_BOLD = 1
  94. Const ATTR_REVERSE = 2
  95.  
  96. Dim parsedata(10) As Integer
  97. Dim ppno As Integer
  98.  
  99. Dim sw_ugoahead As Integer
  100. Dim sw_igoahead As Integer
  101. Dim sw_echo As Integer
  102. Dim sw_linemode As Integer
  103. Dim sw_termsent As Integer
  104. Dim substate As Integer
  105.  
  106. Const GO_NORM = 0
  107. Const GO_ESC1 = 1
  108. Const GO_ESC2 = 2
  109. Const GO_ESC3 = 3
  110. Const GO_ESC4 = 4
  111. Const GO_ESC5 = 5
  112. Const GO_IAC1 = 6
  113. Const GO_IAC2 = 7
  114. Const GO_IAC3 = 8
  115. Const GO_IAC4 = 9
  116. Const GO_IAC5 = 10
  117. Const GO_IAC6 = 11
  118.  
  119. Const SUSP = 237
  120. Const ABORT = 238
  121. Const SE = 240
  122. Const NOP = 241
  123. Const DM = 242
  124. Const break = 243
  125. Const IP = 244
  126. Const AO = 245
  127. Const AYT = 246
  128. Const EC = 247
  129. Const EL = 248
  130. Const GOAHEAD = 249
  131. Const SB = 250
  132. Const WILLTEL = 251
  133. Const WONTTEL = 252
  134. Const DOTEL = 253
  135. Const DONTTEL = 254
  136. Const IAC = 255
  137.  
  138. 'Const BINARY = 0
  139. Const ECHO = 1
  140. Const RECONNECT = 2
  141. Const SGA = 3
  142. Const AMSN = 4
  143. Const STATUS = 5
  144. Const TIMING = 6
  145. Const RCTAN = 7
  146. Const OLW = 8
  147. Const OPS = 9
  148. Const OCRD = 10
  149. Const OHTS = 11
  150. Const OHTD = 12
  151. Const OFFD = 13
  152. Const OVTS = 14
  153. Const OVTD = 15
  154. Const OLFD = 16
  155. Const XASCII = 17
  156. Const LOGOUT = 18
  157. Const BYTEM = 19
  158. Const DET = 20
  159. Const SUPDUP = 21
  160. Const SUPDUPOUT = 22
  161. Const SENDLOC = 23
  162. Const TERMTYPE = 24
  163. Const EOR = 25
  164. Const TACACSUID = 26
  165. Const OUTPUTMARK = 27
  166. Const TERMLOCNUM = 28
  167. Const REGIME3270 = 29
  168. Const X3PAD = 30
  169. Const NAWS = 31
  170. Const TERMSPEED = 32
  171. Const TFLOWCNTRL = 33
  172. Const LINEMODE = 34
  173.                            
  174. Const MODE = 1
  175. 'Const EDIT = 1
  176. Const TRAPSIG = 2
  177. Const MODE_ACK = 4
  178. Const SOFT_TAB = 8
  179. Const LIT_ECHO = 16
  180.  
  181. Const FORWARDMASK = 2
  182.  
  183. Const SLC = 3
  184. Const NO_SUPPORT = 0
  185. Const CANTCHANGE = 1
  186. Const SLC_VALUE = 2
  187. Const SLC_DEFAULT = 3
  188. Const SLC_LEVELBITS = 3
  189. Const SLC_ACK = 128
  190. Const SLC_SYNCH = 1
  191. Const SLC_BRK = 2
  192. Const SLC_IP = 3
  193. Const SLC_AO = 4
  194. Const SLC_AYT = 5
  195. Const SLC_EOR = 6
  196. Const SLC_ABORT = 7
  197. Const SLC_EOF = 8
  198. Const SLC_SUSP = 9
  199. Const SLC_EC = 10
  200. Const SLC_EL = 11
  201. Const SLC_EW = 12
  202. Const SLC_RP = 13
  203. Const SLC_LNEXT = 14
  204. Const SLC_XON = 15
  205. Const SLC_XOFF = 16
  206. Const SLC_FORW1 = 17
  207. Const SLC_FORW2 = 18
  208. Const SLC_MCL = 19
  209. Const SLC_MCR = 20
  210. Const SLC_MCWL = 21
  211. Const SLC_MCWR = 22
  212. Const SLC_MCBOL = 23
  213. Const SLC_MCEOL = 24
  214. Const SLC_INSRT = 25
  215. Const SLC_OVER = 26
  216. Const SLC_ECR = 27
  217. Const SLC_EWR = 28
  218. Const SLC_EBOL = 29
  219. Const SLC_EEOL = 30
  220. Const XDISPLOC = 35
  221. Const XOPTIONS = 255
  222.  
  223. Const Negotiate = 1
  224.  
  225. ' Key Codes
  226.  
  227. Const KEY_LBUTTON = &H1
  228. Const KEY_RBUTTON = &H2
  229. Const KEY_CANCEL = &H3
  230. Const KEY_MBUTTON = &H4    ' NOT contiguous with L & RBUTTON
  231. Const KEY_BACK = &H8
  232. Const KEY_TAB = &H9
  233. Const KEY_CLEAR = &HC
  234. Const KEY_RETURN = &HD
  235. Const KEY_SHIFT = &H10
  236. Const KEY_CONTROL = &H11
  237. Const KEY_MENU = &H12
  238. Const KEY_PAUSE = &H13
  239. Const KEY_CAPITAL = &H14
  240. Const KEY_ESCAPE = &H1B
  241. Const KEY_SPACE = &H20
  242. Const KEY_PRIOR = &H21
  243. Const KEY_NEXT = &H22
  244. Const KEY_END = &H23
  245. Const KEY_HOME = &H24
  246. Const KEY_LEFT = &H25
  247. Const KEY_UP = &H26
  248. Const KEY_RIGHT = &H27
  249. Const KEY_DOWN = &H28
  250. Const KEY_SELECT = &H29
  251. Const KEY_PRINT = &H2A
  252. Const KEY_EXECUTE = &H2B
  253. Const KEY_SNAPSHOT = &H2C
  254. Const KEY_INSERT = &H2D
  255. Const KEY_DELETE = &H2E
  256. Const KEY_HELP = &H2F
  257.  
  258. ' KEY_A thru KEY_Z are the same as their ASCII equivalents: 'A' thru 'Z'
  259. ' KEY_0 thru KEY_9 are the same as their ASCII equivalents: '0' thru '9'
  260.  
  261. Const KEY_NUMPAD0 = &H60
  262. Const KEY_NUMPAD1 = &H61
  263. Const KEY_NUMPAD2 = &H62
  264. Const KEY_NUMPAD3 = &H63
  265. Const KEY_NUMPAD4 = &H64
  266. Const KEY_NUMPAD5 = &H65
  267. Const KEY_NUMPAD6 = &H66
  268. Const KEY_NUMPAD7 = &H67
  269. Const KEY_NUMPAD8 = &H68
  270. Const KEY_NUMPAD9 = &H69
  271. Const KEY_MULTIPLY = &H6A
  272. Const KEY_ADD = &H6B
  273. Const KEY_SEPARATOR = &H6C
  274. Const KEY_SUBTRACT = &H6D
  275. Const KEY_DECIMAL = &H6E
  276. Const KEY_DIVIDE = &H6F
  277. Const KEY_F1 = &H70
  278. Const KEY_F2 = &H71
  279. Const KEY_F3 = &H72
  280. Const KEY_F4 = &H73
  281. Const KEY_F5 = &H74
  282. Const KEY_F6 = &H75
  283. Const KEY_F7 = &H76
  284. Const KEY_F8 = &H77
  285. Const KEY_F9 = &H78
  286. Const KEY_F10 = &H79
  287. Const KEY_F11 = &H7A
  288. Const KEY_F12 = &H7B
  289. Const KEY_F13 = &H7C
  290. Const KEY_F14 = &H7D
  291. Const KEY_F15 = &H7E
  292. Const KEY_F16 = &H7F
  293.  
  294. Const KEY_NUMLOCK = &H90
  295.  
  296. Sub cursor_timer_Timer ()
  297.  
  298.   draw_cursor
  299.  
  300. End Sub
  301.  
  302. Sub draw_cursor ()
  303.  
  304. Dim x As Integer
  305. Dim y As Integer
  306.  
  307.     If cursor_is_on Then
  308.       cursor_is_on = False
  309.     Else
  310.       cursor_is_on = True
  311.     End If
  312.       
  313.     If cursor_is_on Then
  314.       x = col * txtw
  315.       y = row * txth
  316.       telnet_form.DrawMode = 6
  317.       telnet_form.Line (x, y)-(x + txtw, y + txth), , BF
  318.       telnet_form.DrawMode = 16
  319.     End If
  320.  
  321. End Sub
  322.  
  323. Function esc1 (ch As String) As Integer
  324.     
  325.   esc1 = GO_NORM             ' default return value is normal character
  326.  
  327.   Select Case ch
  328.     Case Chr$(8)             ' embedded backspace
  329.       col = col - 1
  330.     Case "7"                 ' save cursor
  331.       save_row = row
  332.       save_col = col
  333.     Case "8"                 ' restore cursor
  334.       row = save_row
  335.       col = save_col
  336.     Case "c"                 ' look at VSIreset()
  337.     Case "D"                 ' cursor down
  338.       row = row + 1
  339.     Case "E"                 ' next line
  340.       row = row + 1
  341.       col = 0
  342.     Case "H"                 ' set tab
  343.       tab_table(tabno) = col
  344.       tabno = tabno + 1
  345.     Case "I"                 ' look at bp_ESC_I()
  346.     Case "M"                 ' cursor up
  347.       row = row - 1
  348.     Case "Z"                 ' send ident
  349.     Case "["                 ' requires further processing
  350.       Erase parm
  351.       pno = 0
  352.       esc1 = GO_ESC2
  353.     Case ">"                 ' DECPAM off
  354.     Case "="                 ' DECPAM on
  355.     Case "#"                 ' requires further processing
  356.       Erase parm
  357.       pno = 0
  358.       esc1 = GO_ESC3
  359.     Case "("                 ' requires further processing
  360.       Erase parm
  361.       pno = 0
  362.       esc1 = GO_ESC4
  363.     Case ")"                 ' requires further processing
  364.       Erase parm
  365.       pno = 0
  366.       esc1 = GO_ESC5
  367.   End Select
  368.  
  369. End Function
  370.  
  371. Function esc2 (ch As String) As Integer
  372.     
  373.   ' handle ESC [ sequences
  374.  
  375.   esc2 = GO_NORM
  376.  
  377.   Select Case ch
  378.     Case Chr$(8)             ' backspace
  379.       col = col - 1
  380.       esc2 = GO_ESC2
  381.     Case "0" To "9"          ' numeric parameters
  382.       parm(pno) = parm(pno) * 10 + Val(ch$)
  383.       esc2 = GO_ESC2
  384.     Case "?"                 ' default (no) parameter
  385.       parm(pno) = -2
  386.       pno = pno + 1
  387.       esc2 = GO_ESC2
  388.     Case ";"                 ' parameter separator
  389.       pno = pno + 1
  390.       esc2 = GO_ESC2
  391.     Case "A"                 ' cursor back n rows
  392.       If parm(0) < 1 Then
  393.          row = row - 1
  394.       Else
  395.         row = row - parm(0)
  396.       End If
  397.     Case "B"                 ' cursor forward n rows
  398.       If parm(0) < 1 Then
  399.         row = row + 1
  400.       Else
  401.         row = row + parm(0)
  402.       End If
  403.     Case "C"                 ' cursor forward n cols
  404.       If parm(0) < 1 Then
  405.         col = col + 1
  406.       Else
  407.         col = col + parm(0)
  408.       End If
  409.     Case "D"                 ' cursor back n columns
  410.       If parm(0) < 1 Then
  411.         col = col - 1
  412.       Else
  413.         col = col - parm(0)
  414.       End If
  415.     Case "H"                 ' set cursor address
  416.       row = parm(0) - 1
  417.       col = parm(1) - 1
  418.     Case "J"
  419.       test_bounds
  420.       Select Case parm(0)
  421.         Case -1, 0           ' erase from cursor to end of screen
  422.           telnet_form.Line (col * txtw, row * txth)-(telnet_form.Width, (row + 1) * txth), , BF
  423.           telnet_form.Line (0, (row + 1) * txth)-(telnet_form.Width, telnet_form.Height), , BF
  424.           comm_buffer(row) = Left$(comm_buffer(row), col)
  425.           For y = row + 1 To 23
  426.             comm_buffer(y) = ""
  427.           Next y
  428.         Case 1               ' erase from screen begin to cursor
  429.           telnet_form.Line (0, 0)-(telnet_form.Width, row * txth), , BF
  430.           telnet_form.Line (0, row * txth)-(col * txtw, (row + 1) * txth), , BF
  431.           comm_buffer(row) = Space$(col) + Right$(comm_buffer(row), Len(comm_buffer(row)) - col)
  432.           For y = 0 To row - 1
  433.             comm_buffer(y) = ""
  434.           Next y
  435.         Case 2               ' erase entire screen
  436.           telnet_form.Cls
  437.           For y = 0 To 23
  438.             comm_buffer(y) = ""
  439.           Next y
  440.       End Select
  441.     Case "K"
  442.       test_bounds
  443.       Select Case parm(0)
  444.         Case -1, 0           ' erase from cursor to end of line
  445.           telnet_form.Line (col * txtw, row * txth)-(telnet_form.Width, (row + 1) * txth), , BF
  446.           comm_buffer(row) = Left$(comm_buffer(row), col)
  447.         Case 1               ' erase from begin of line to cursor
  448.           telnet_form.Line (0, row * txth)-((col + 1) * txtw, (row + 1) * txth), , BF
  449.           comm_buffer(row) = Space$(col) + Right$(comm_buffer(row), Len(comm_buffer(row)) - col)
  450.         Case 2               ' erase entire line
  451.           telnet_form.Line (0, row * txth)-(Width, (row + 1) * txth), , BF
  452.           comm_buffer(row) = ""
  453.       End Select
  454.     Case "L"                 ' insert lines
  455.     Case "M"                 ' delete lines
  456.     Case "P"                 ' delete characters
  457.     Case "c"                 ' look at VTsendident()
  458.     Case "f"
  459.       row = parm(0) - 1
  460.       col = parm(1) - 1
  461.     Case "g"                 ' clear tabs
  462.     Case "h"                 ' look at VSIsetoption(1)
  463.     Case "i"                 ' print though mode
  464.     Case "l"                 ' look at VSIsetoption(0)
  465.     Case "m"
  466.       For y = 0 To pno
  467.         Select Case parm(y)
  468.           Case Is < 1       ' reset attributes
  469.             attributes = 0
  470.           Case 1            ' bold
  471.             attributes = attributes Or ATTR_BOLD
  472.           Case 4            ' underline
  473.           Case 5            ' blink
  474.           Case 6            ' blink
  475.           Case 7            ' reverse
  476.             attributes = attributes Or ATTR_REVERSE
  477.         End Select
  478.       Next y
  479.     Case "n"
  480.       Select Case parm(0)
  481.         Case 5               ' look at VTsendstat()
  482.         Case 6               ' look at VTsendpos
  483.       End Select
  484.     Case "q"
  485.     Case "r"                 ' set window bounds (top, bottom)
  486.   End Select
  487.  
  488. End Function
  489.  
  490. Function esc3 (ch As String) As Integer
  491.  
  492.   ' handle ESC # sequences
  493.  
  494.   esc3 = GO_NORM
  495.  
  496.   Select Case ch
  497.     Case Chr$(8)
  498.       col = col - 1
  499.       esc3 = GO_ESC3
  500.     Case "8"                 ' look at VTalign()
  501.   End Select
  502.  
  503. End Function
  504.  
  505. Function esc4 (ch As String) As Integer
  506.     
  507.   ' handle ESC ( sequences
  508.  
  509.   esc4 = GO_NORM
  510.  
  511.   Select Case ch
  512.     Case Chr$(8)
  513.       col = col - 1
  514.       esc4 = GO_ESC4
  515.     Case "A", "B", "1"       ' select text character set
  516.       graphics = False
  517.     Case "0", "2"            ' select graphic character set
  518.       graphics = True
  519.   End Select
  520.  
  521. End Function
  522.  
  523. Function esc5 (ch As String) As Integer
  524.     
  525.   ' handle ESC ) sequences
  526.  
  527.   esc5 = GO_NORM
  528.     
  529.   Select Case ch
  530.     Case Chr$(8)
  531.       col = col - 1
  532.       esc5 = GO_ESC5
  533.     Case "A", "B", "1"       ' select text character set
  534.       graphics = False
  535.     Case "0", "2"            ' select graphic character set
  536.       graphics = True
  537.   End Select
  538.  
  539. End Function
  540.  
  541. Sub font_7_menu_Click ()
  542.   
  543.   telnet_form.FontSize = 7.5
  544.  
  545.   font_7_menu.Checked = True
  546.   font_9_menu.Checked = False
  547.   
  548.   txth = telnet_form.TextHeight("A")
  549.   txtw = telnet_form.TextWidth("A")
  550.  
  551.   telnet_form.Height = txth * 30
  552.   telnet_form.Width = txtw * 82
  553.   telnet_form.Left = 500
  554.   telnet_form.Top = 500
  555. End Sub
  556.  
  557. Sub font_9_menu_Click ()
  558.  
  559.   telnet_form.FontSize = 9
  560.  
  561.   font_7_menu.Checked = False
  562.   font_9_menu.Checked = True
  563.  
  564.   txth = telnet_form.TextHeight("A")
  565.   txtw = telnet_form.TextWidth("A")
  566.  
  567.   telnet_form.Height = txth * 30
  568.   telnet_form.Width = txtw * 82
  569.   telnet_form.Left = 0
  570.   telnet_form.Top = 0
  571.  
  572. End Sub
  573.  
  574. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  575.   
  576.   Dim ch As String
  577.     
  578.   ch = Chr$(0)
  579.     
  580.   Select Case KeyCode
  581.     Case KEY_RETURN
  582.       cursor_timer.Enabled = False
  583.       x = col * txtw
  584.       y = row * txth
  585.       DrawMode = 16
  586.       Line (x, y)-(x + txtw, y + txth), , BF
  587.     Case KEY_CONTROL
  588.       control_on = True
  589.     Case KEY_END
  590.       ch = Chr$(27) + "[K"
  591.     Case KEY_HOME
  592.       ch = Chr$(27) + "[H"
  593.     Case KEY_LEFT
  594.       ch = Chr$(27) + "[D"
  595.     Case KEY_UP
  596.       ch = Chr$(27) + "[A"
  597.     Case KEY_RIGHT
  598.       ch = Chr$(27) + "[C"
  599.     Case KEY_DOWN
  600.       ch = Chr$(27) + "[B"
  601.     Case KEY_F1
  602.       ch = Chr$(27) + "OP"
  603.     Case KEY_F2
  604.       ch = Chr$(27) + "OQ"
  605.     Case KEY_F3
  606.       ch = Chr$(27) + "OR"
  607.     Case KEY_F4
  608.       ch = Chr$(27) + "OS"
  609.     Case Else
  610.       If control_on And KeyCode > 63 Then
  611.         ch = Chr$(KeyCode - 64)
  612.       End If
  613.   End Select
  614.  
  615.   If ch > Chr$(0) And WinSock1.Open Then
  616.     WinSock1.Send = ch
  617.   End If
  618.  
  619. End Sub
  620.  
  621. Sub Form_KeyPress (KeyAscii As Integer)
  622.   
  623. Dim ch As String
  624.     
  625.   ch = Chr$(KeyAscii)
  626.   
  627.   If control_on Then
  628.     If KeyAscii > 63 Then
  629.       ch = Chr$(KeyAscii - 64)
  630.     Else
  631.       ch = Chr$(0)
  632.     End If
  633.   End If
  634.   
  635.   If ch > Chr$(0) And WinSock1.Open Then
  636.     WinSock1.Send = ch
  637.   End If
  638.  
  639. End Sub
  640.  
  641. Sub Form_KeyUp (KeyCode As Integer, Shift As Integer)
  642.     
  643.     Select Case KeyCode
  644.       Case KEY_CONTROL
  645.         control_on = False
  646.     End Select
  647.  
  648. End Sub
  649.  
  650. Sub Form_Load ()
  651.  
  652.     'telnet_form.windowstate = MAXIMIZED
  653.      
  654.     cursor_timer.Enabled = False
  655.   
  656.     telnet_form.FontSize = 7.5
  657.     font_7_menu.Checked = True
  658.     font_9_menu.Checked = False
  659.  
  660.     txth = telnet_form.TextHeight("A")
  661.     txtw = telnet_form.TextWidth("A")
  662.  
  663.     telnet_form.Left = 500
  664.     telnet_form.Top = 500
  665.     telnet_form.Height = txth * 30
  666.     telnet_form.Width = txtw * 82
  667.  
  668.     row = 0
  669.     col = 0
  670.     save_row = 0
  671.     save_col = 0
  672.     tabno = 0
  673.     graphics = False
  674.     sw_echo = True
  675.     
  676.     For x = 0 To 23
  677.       comm_buffer(x) = ""
  678.     Next x
  679.     
  680.     For x = 0 To 19
  681.       tab_table(x) = 0
  682.     Next x
  683.  
  684.     graph_chars = "ABCDEFGHI" + Chr$(217) + Chr$(191) + Chr$(218) + Chr$(192) + "NOP" + Chr$(196) + "RSTUVW" + Chr$(179) + "YZ"
  685.     
  686.     If Command$ = "" Then
  687.       menu_connect_click
  688.     Else
  689.       WinSock1.IPName = Trim$(Command$)
  690.       WinSock1.Port = 23
  691.       WinSock1.Open = True
  692.       msg$ = Chr$(IAC) + Chr$(DOTEL) + Chr$(ECHO)
  693.       msg$ = msg$ + Chr$(IAC) + Chr$(DOTEL) + Chr$(SGA)
  694.       msg$ = msg$ + Chr$(IAC) + Chr$(WILLTEL) + Chr$(NAWS)
  695.       WinSock1.Send = msg$
  696.       menu_connect.Enabled = False
  697.     End If
  698.  
  699. End Sub
  700.  
  701. Sub Form_Unload (Cancel As Integer)
  702.  
  703.   If WinSock1.Open = True Then
  704.     WinSock1.Open = False
  705.   End If
  706.  
  707. End Sub
  708.  
  709. Function iac1 (ch As String) As Integer
  710.       
  711.   iac1 = GO_NORM
  712.   
  713.   Select Case Asc(ch)
  714.     Case DOTEL
  715.       Debug.Print "DO ";
  716.       iac1 = GO_IAC2
  717.     Case DONTTEL
  718.       Debug.Print "DONT "
  719.     Case WILLTEL
  720.       Debug.Print "WILL ";
  721.       iac1 = GO_IAC3
  722.     Case WONTTEL
  723.       Debug.Print "WONT ";
  724.       iac1 = GO_IAC4
  725.     Case SB
  726.       Debug.Print "SB ";
  727.       iac1 = GO_IAC5
  728.       pno = 0
  729.       substate = 0
  730.     Case SE
  731.       Debug.Print "SE "
  732.       ' End of negotiation string, string is in parsedata()
  733.       Select Case parsedata(0)
  734.         Case TERMTYPE
  735.           If parsedata(1) = 1 Then
  736.             Debug.Print "SENT: SB TERMTYPE VT100"
  737.             telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(SB) + Chr$(TERMTYPE) + "vt100" + Chr$(0) + Chr$(IAC) + Chr$(SE)
  738.           End If
  739.       End Select
  740.   End Select
  741.   
  742. End Function
  743.  
  744. Function iac2 (ch As String) As Integer
  745.       
  746.   'DO Processing
  747.   
  748.   iac2 = GO_NORM
  749.  
  750.   Select Case Asc(ch)
  751.     Case SGA
  752.       Debug.Print "SGA"
  753.       If Not sw_igoahead Then
  754.         telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(WILLTEL) + Chr$(SGA)
  755.         sw_igoahead = True
  756.       End If
  757.     Case TERMTYPE
  758.       Debug.Print "TERMTYPE"
  759.       If Not sw_termsent Then
  760.         sw_termsent = True
  761.         telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(WILLTEL) + Chr$(TERMTYPE)
  762.       End If
  763.     Case NAWS
  764.       Debug.Print "NAWS"
  765.       telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(SB) + Chr$(NAWS) + Chr$(0) + Chr$(80) + Chr$(0) + Chr$(24) + Chr$(IAC) + Chr$(SE)
  766.     Case Else
  767.       Debug.Print "OTHER"
  768.       telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(WONTTEL) + ch
  769.   End Select
  770.  
  771. End Function
  772.  
  773. Function iac3 (ch As String) As Integer
  774.       
  775.   ' WILL Processing
  776.   
  777.   iac3 = GO_NORM
  778.       
  779.   Select Case Asc(ch)
  780.     Case SGA
  781.       Debug.Print "SGA"
  782.       If Not sw_ugoahead Then
  783.         sw_ugoahead = True
  784.         telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(DOTEL) + Chr$(SGA)
  785.         Debug.Print "SENT: DO SGA"
  786.       End If
  787.     Case ECHO
  788.       Debug.Print "ECHO"
  789.       If Not sw_echo Then
  790.         sw_echo = True
  791.         telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(DOTEL) + Chr$(ECHO)
  792.         Debug.Print "SENT: DO ECHO"
  793.       End If
  794.     Case TIMING
  795.       Debug.Print "TIMING"
  796.       sw_timing = 0
  797.     Case Else
  798.       Debug.Print "SENT:  DONT OTHER"
  799.       telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(DONTTEL) + ch
  800.   End Select
  801.  
  802. End Function
  803.  
  804. Function iac4 (ch As String) As Integer
  805.  
  806.   ' WONT Processing
  807.   
  808.   iac4 = GO_NORM
  809.   
  810.   Select Case Asc(ch)
  811.     Case ECHO
  812.       Debug.Print "ECHO"
  813.       If sw_echo Then
  814.         sw_echo = False
  815.         telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(DONTTEL) + Chr$(ECHO)
  816.         Debug.Print "SENT: DONT ECHO"
  817.       End If
  818.     Case TIMING
  819.       Debug.Print "TIMING"
  820.       sw_timing = 0
  821.     Case Else
  822.       Debug.Print "SENT: DONT OTHER"
  823.       telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(DONT) + ch
  824.   End Select
  825.  
  826. End Function
  827.  
  828. Function iac5 (ch As String) As Integer
  829.  
  830.   ' Collect parms after SB and until another IAC
  831.   
  832.   ich = Asc(ch)
  833.   
  834.   If ich = IAC Then
  835.     iac5 = GO_IAC1
  836.     Exit Function
  837.   End If
  838.  
  839.   Debug.Print "SUBPARM ";
  840.   parsedata(ppno) = ich
  841.   ppno = ppno + 1
  842.  
  843.   iac5 = GO_IAC5
  844.  
  845. End Function
  846.  
  847. Function iac6 (ch As String) As Integer
  848.   
  849.   ' End of negotiation string, string is in parsedata()
  850.  
  851.   Select Case parsedata(0)
  852.     Case TERMTYPE
  853.       If parsedata(1) = 1 Then
  854.         Debug.Print "SENT: SB TERMTYPE VT100"
  855.         telnet_form.WinSock1.Send = Chr$(IAC) + Chr$(SB) + Chr$(TERMTYPE) + "vt100" + Chr$(0) + Chr$(IAC) + Chr$(SE)
  856.       End If
  857.   End Select
  858.  
  859. End Function
  860.  
  861. Sub menu_connect_click ()
  862.  
  863.   If WinSock1.Open = True Then
  864.     WinSock1.Open = False
  865.   End If
  866.  
  867.   connect_form.Show 1
  868.   Unload connect_form
  869.   If WinSock1.IPName <> "" And WinSock1.Port <> 0 And WinSock1.Open = False Then
  870.     WinSock1.Open = True
  871.     msg$ = Chr$(IAC) + Chr$(DOTEL) + Chr$(ECHO)
  872.     msg$ = msg$ + Chr$(IAC) + Chr$(DOTEL) + Chr$(SGA)
  873.     msg$ = msg$ + Chr$(IAC) + Chr$(WILLTEL) + Chr$(NAWS)
  874.     WinSock1.Send = msg$
  875.     Debug.Print "SENT: DO ECHO"
  876.     Debug.Print "SENT: DO SGA"
  877.     Debug.Print "SENT: WILL NAWS"
  878.   End If
  879.  
  880. End Sub
  881.  
  882. Sub menu_disconnect_Click ()
  883.  
  884.   If WinSock1.Open = True Then
  885.     WinSock1.Open = False
  886.     draw_cursor
  887.     menu_connect_click
  888.   End If
  889.  
  890. End Sub
  891.  
  892. Sub menu_exit_Click ()
  893.  
  894.   If WinSock1.Open Then
  895.     WinSock1.Open = False
  896.   End If
  897.   End
  898.  
  899. End Sub
  900.  
  901. Function norm_char (ch As String) As Integer
  902.  
  903. Dim ich As Integer
  904. Dim x As Integer
  905. Dim y As Integer
  906.  
  907.   If ch < Chr$(32) Then
  908.     ich = Asc(ch)
  909.     Select Case ich
  910.       Case 7                 ' bell
  911.         Beep
  912.       Case 8                 ' backspace
  913.         col = col - 1
  914.       Case 9                 ' tab
  915.         For y = 0 To 19
  916.           If col < tab_table(y) Then
  917.             Exit For
  918.           End If
  919.         Next y
  920.         col = tab_table(y)
  921.       Case 10                ' line feed
  922.         row = row + 1
  923.       Case 11                ' vertical tab
  924.         row = row + 1
  925.       Case 12                ' form feed
  926.         row = row + 1
  927.       Case 13                ' carriage return
  928.         col = 0
  929.       Case 14                ' set graphics mode
  930.       Case 15                ' set character mode
  931.       Case 27
  932.         norm_char = GO_ESC1
  933.     End Select
  934.   ElseIf ch = Chr$(IAC) Then
  935.     norm_char = GO_IAC1
  936.   Else
  937.     test_bounds
  938.     
  939.     If graphics Then
  940.       ch = Mid$(graph_chars, Asc(UCase$(ch)) - 64, 1)
  941.     End If
  942.       
  943.     x = col * txtw
  944.     y = row * txth
  945.     telnet_form.Line (x, y)-(x + txtw, y + txth), , BF
  946.     telnet_form.CurrentX = x
  947.     telnet_form.CurrentY = y
  948.     telnet_form.Print ch;
  949.       
  950.     If attributes And ATTR_BOLD Then
  951.       telnet_form.CurrentX = x + 8
  952.       telnet_form.CurrentY = y
  953.       telnet_form.Print ch;
  954.     End If
  955.       
  956.     If attributes And ATTR_REVERSE Then
  957.       telnet_form.CurrentX = x
  958.       telnet_form.CurrentY = y
  959.       telnet_form.DrawMode = 6
  960.       telnet_form.Line (x, y)-(x + txtw, y + txth), , BF
  961.       telnet_form.DrawMode = 16
  962.     End If
  963.       
  964.     Mid$(comm_buffer(row), col + 1, 1) = ch
  965.     col = col + 1
  966.       
  967.   End If
  968.  
  969. End Function
  970.  
  971. Sub test_bounds ()
  972.     
  973. Dim y As Integer
  974.  
  975.   If row < 0 Then
  976.     row = 0
  977.   End If
  978.  
  979.   If col < 0 Then
  980.     col = 0
  981.   ElseIf col > 79 Then
  982.     col = 0
  983.     row = row + 1
  984.   End If
  985.  
  986.   ' test for next row past the botton of the screen.  if it is
  987.   ' scroll the entire screen up one row.  this is a good place
  988.   ' to add logic for a scroll back buffer
  989.  
  990.   If row > 23 Then
  991.     telnet_form.Cls
  992.     For row = 0 To 22
  993.       comm_buffer(row) = comm_buffer(row + 1)
  994.       blk$ = blk$ + comm_buffer(row) + Chr$(13) + Chr$(10)
  995.     Next row
  996.     telnet_form.Print blk$
  997.     comm_buffer(23) = ""
  998.     row = 23
  999.   End If
  1000.    
  1001. End Sub
  1002.  
  1003. Sub WinSock1_Recv ()
  1004.     
  1005. Dim x As Integer
  1006. Dim y As Integer
  1007. Dim ch As String * 1
  1008.  
  1009. Static cmd As Integer
  1010.  
  1011.   cursor_timer.Enabled = False
  1012.   x = col * txtw
  1013.   y = row * txth
  1014.   DrawMode = 16
  1015.   Line (x, y)-(x + txtw, y + txth), , BF
  1016.  
  1017.   msg$ = WinSock1.Recv
  1018.   
  1019.   For x = 1 To Len(msg$)
  1020.     ch = Mid$(msg$, x, 1)
  1021.     Select Case cmd
  1022.       Case GO_NORM
  1023.         cmd = norm_char(ch)
  1024.       Case GO_ESC1
  1025.         cmd = esc1(ch)
  1026.       Case GO_ESC2
  1027.         cmd = esc2(ch)
  1028.       Case GO_ESC3
  1029.         cmd = esc3(ch)
  1030.       Case GO_ESC4
  1031.         cmd = esc4(ch)
  1032.       Case GO_ESC5
  1033.         cmd = esc5(ch)
  1034.       
  1035.       Case GO_IAC1
  1036.         cmd = iac1(ch)
  1037.       Case GO_IAC2
  1038.         cmd = iac2(ch)
  1039.       Case GO_IAC3
  1040.         cmd = iac3(ch)
  1041.       Case GO_IAC4
  1042.         cmd = iac4(ch)
  1043.       Case GO_IAC5
  1044.         cmd = iac5(ch)
  1045.       Case GO_IAC6
  1046.         cmd = iac6(ch)
  1047.       Case Else
  1048.         MsgBox "Invalid 'next (" + Str$(cmd) + ")' processing routine in cmd loop"
  1049.     End Select
  1050.   Next x
  1051.   
  1052.   cursor_timer.Enabled = True
  1053.  
  1054. End Sub
  1055.  
  1056.